<?php require_once('../Connections/con_gl.php'); ?>
<?php
$getquery = str_replace("+"," ",$_GET[query]);
mysql_select_db($database_con_gl, $con_gl);
$query_rtrans = stripslashes($getquery);
$rtrans = mysql_query($query_rtrans, $con_gl) or die(mysql_error());
$row_rtrans = mysql_fetch_assoc($rtrans);
$totalRows_rtrans = mysql_num_rows($rtrans);

mysql_select_db($database_con_gl, $con_gl);
$query_getcompany = "SELECT * FROM gl_company WHERE id = 1";
$getcompany = mysql_query($query_getcompany, $con_gl) or die(mysql_error());
$row_getcompany = mysql_fetch_assoc($getcompany);
$totalRows_getcompany = mysql_num_rows($getcompany);
?>
<div>
  <table width="100%" border="0" cellspacing="0" cellpadding="2">
    <tr valign="middle">
      <td width="10%" height="115" align="center" style="border:dashed 1px #333333;">LOGO</td>
      <td width="90%" height="115" align="center"><?php echo $row_getcompany['perusahaan']; ?><br>
      <?php echo $row_getcompany['alamat']; ?><br>
      Telp.<?php echo $row_getcompany['telp']; ?> Fax.<?php echo $row_getcompany['fax']; ?> </td>
      <td width="1%" height="115">&nbsp;</td>
    </tr>
	<tr valign="middle">
      <td align="center">&nbsp;</td>
      <td align="center">&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
  </table>
</div>
<?php do { ?>
<?php
mysql_select_db($database_con_gl, $con_gl);
$query_trans = "SELECT gl_trans.transaksi, gl_trans.pos, gl_trans.total, gl_trans.jumlah, gl_trans.hargasatuan, gl_trans.diskon, gl_trans.barang, gl_trans.tglretur, gl_trans.tglbayar FROM gl_trans WHERE gl_trans.no_ref='$row_rtrans[no_ref]' ORDER BY gl_trans.pos";
$trans = mysql_query($query_trans, $con_gl) or die(mysql_error());
$row_trans = mysql_fetch_assoc($trans);
$totalRows_trans = mysql_num_rows($trans);
?>
<span style="font-weight: bold"><?php echo $row_rtrans['no_ref']; ?> - <?php echo $row_rtrans['keterangan'];?></span>
  <table width="100%" border="1" cellpadding="4" cellspacing="0" bordercolor="#000000">
    <tr bgcolor="#CCCCCC">
      <td width="8%"><span style="font-weight: bold">Tanggal</span></td>
      <td width="28%"><span style="font-weight: bold">Transaksi</span></td>
      <td width="20%"><strong>Barang</strong></td>
      <td width="6%"><strong>Jumlah</strong></td>
      <td width="8%"><strong>Harga </strong></td>
      <td width="6%"><strong>Diskon (%) </strong></td>
      <td width="12%"><span style="font-weight: bold">Debet</span></td>
      <td width="12%"><span style="font-weight: bold">Kredit</span></td>
    </tr>
	<?php $totd =0; $totk = 0; do { ?>
	<?php
	if(is_numeric($row_trans['barang'])) {
mysql_select_db($database_con_gl, $con_gl);
$query_cekbrg = "SELECT gl_barang.barang FROM gl_barang where id='$row_trans[barang]'";
$cekbrg = mysql_query($query_cekbrg, $con_gl) or die(mysql_error());
$row_cekbrg = mysql_fetch_assoc($cekbrg);
$totalRows_cekbrg = mysql_num_rows($cekbrg);
$barang = $row_cekbrg['barang'];
}else{
$barang =$row_trans['barang'];
}
	?>
    <tr valign="top">
      <td><?php if($row_trans['tglretur']<>'' OR $row_trans['tglbayar']<>'') { echo $row_trans['tglretur'];$row_trans['tglbayar'];}else{ echo $row_rtrans['tgl'];} ?></td>
      <td><?php echo $row_trans['transaksi']; ?></td>
      <td align="left"><?php if($row_trans['hargasatuan']<>'') { echo $barang;}else{ echo "--";}?></td>
      <td align="right"><?php echo $row_trans['jumlah']; ?></td>
      <td align="right"><?php if($row_trans['hargasatuan']<>'') { echo number_format($row_trans['hargasatuan'],0,',','.').",-";} ?></td>
      <td align="right"><?php echo $row_trans['diskon']; ?></td>
      <td align="right"><?php if($row_trans['pos']=='D') { echo number_format($row_trans['total'],0,',','.').",-";$totd += $row_trans[total];}else{ echo "0,00";} ?></td>
      <td align="right"><?php if($row_trans['pos']=='K') { echo number_format($row_trans['total'],0,',','.').",-";$totk += $row_trans[total];}else{ echo "0,00";} ?></td>
    </tr>
	<?php } while ($row_trans = mysql_fetch_assoc($trans)); ?>
    <tr valign="top">
      <td colspan="6" align="right"><span style="font-weight: bold">Total :</span></td>
      <td align="right"><?php echo number_format($totd,0,',','.').",-";?></td>
      <td align="right"><?php echo number_format($totk,0,',','.').",-";?></td>
    </tr>
  </table>
  
<?php } while ($row_rtrans = mysql_fetch_assoc($rtrans)); 
mysql_free_result($trans);
?>